package me.chan.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.function.Predicate;

public class LamdaDemo {

	public static void main(String[] args) {
		/*List<Integer> list = map(Arrays.asList("HelloWorld","world","jdk1.8"),
				(String s) -> s.length());
		System.out.println(list);*/
		
		/*List<Boolean> list = map(Arrays.asList("Hello", "world", ""),
				(String s1) -> s1.isEmpty());
		System.out.println(list);*/
		
		IntPredicate even = (int i) -> i % 2 == 0;
		// Not boxing  --> true
		System.out.println(even.test(1000));
		Predicate<Integer> odd = (Integer i) -> i % 2 == 1;
		//boxing   --> false
		System.out.println(odd.test(1000));
		
		
	}

	
	public static <T, R> List<R> map(List<T> list, Function<T, R> f) {
		List<R> result = new ArrayList<>();
		for (T t : list) {
			result.add(f.apply(t));
		}
		return result;
	}
}
